package  
{
	import flash.utils.ByteArray;
	import net.flashpunk.Entity;
	import net.flashpunk.graphics.Spritemap;
	import net.flashpunk.FP;
	import net.flashpunk.graphics.Text;
	/**
	 * © 2012 TheJavaArcade.com
	 */	
	public class Fruit extends Entity {
		public var fruitSprite:Spritemap = new Spritemap(Assets.FRUIT_TILES, 15, 12);
		public var theText:Text;
		public var count:int;
		public var state:int;
		public var level:int;
		
		public function Fruit(theLevel:int) {
			level = theLevel;
			theText = new Text("");
			theText.size = 8;
			layer = 0;
			fruitSprite.add("pear", [0], 1, false);
			fruitSprite.add("apple", [1], 1, false);
			fruitSprite.add("banana", [2], 1, false);
			fruitSprite.add("egg", [3], 1, false);
			setHitbox(10, 10, -2, -1);
			graphic = fruitSprite;
			count = 0;
			state = 0;
		}
		
		override public function update():void {
			if (level == GameEngine.level) {
				if (collide("fracas", x, y) && state == 0) {
					GameEngine.score += 1000;
					if (type == "apple") {
						GameEngine.fracas.jump++;
						theText.text = "Jump +1";
					}
					if (type == "pear") {
						GameEngine.fracas.speed++;
						theText.text = "Speed +1";
					}
					if (type == "banana") {
						GameEngine.fracas.strength++;
						theText.text = "Strength +1";
					}
					if (type == "egg") {
						GameEngine.fracas.regeneration++;
						theText.text = "Regeneration +1";
					}
					graphic = theText;
					state = 1;
					count = 30;
					y = y - 20;
				}
				if (state == 1) {
					count--;
					x = (GameEngine.fracas.x+9) -(theText.width/2);
					y = y - 1;
					if(count==0)FP.world.remove(this);
				}
			}
		}
	}

}